package com.kaizzi.data.jdl.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kaizzi.data.common.utils.DateUtil;
import com.kaizzi.data.jdl.entity.LogHistory;
import com.kaizzi.data.jdl.mapper.LogMapper;
import com.kaizzi.data.jdl.service.LogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author Kzen
 * @Description description
 * @date 2020/10/20
 */
@Service
public class LogServiceImpl extends ServiceImpl<LogMapper, LogHistory> implements LogService {

    private static final String projectName = "jdl";
    private static final String category1 = "ppt";
    private static final String category2 = "data";

    @Resource
    private LogMapper logMapper;
    @Override
    public void recordLog(String status,int category) {
        LogHistory logHistory = new LogHistory();
        logHistory.setProjectName(projectName);
        logHistory.setCategory(category2);
        if (category == 1){
            logHistory.setCategory(category1);
        }
        logHistory.setDataTime(DateUtil.getLastSundayFormat());
        logHistory.setStatus(status);
        logHistory.setCreateTime(DateUtil.getDateTimeNow());
        logMapper.insert(logHistory);
    }

    @Override
    public void setDataLogStatus(String status) {

        if (status.equals("ppt-success") && logMapper.selectById(896L).getStatus().equals("ppt-error")){
            System.out.println("aasdf");
            return;
        }
        LogHistory logHistory = new LogHistory();
        logHistory.setId(896L);
        logHistory.setDataTime(DateUtil.getLastSundayFormat());
        logHistory.setStatus(status);
        logMapper.updateById(logHistory);
    }
}
